/* 将geojson数据转换为feature对象 */
function JsonToFeature(data) {
  let format = new window.ol.format.GeoJSON();
  if (data.type === "FeatureCollection") {
      return format.readFeatures(data);
  } else {
      return format.readFeature(data);
  }
}

/* 将feature对象转换为geojson数据 */
function FeatureToJson(feature) {
  let format = new window.ol.format.GeoJSON();
  if (feature instanceof Array) {
      return format.writeFeaturesObject(feature);
  } else {
      return format.writeFeatureObject(feature);
  }
}

export { JsonToFeature, FeatureToJson };
